//
//  CaiZhuHomeBtnCell.m
//  YJB
//
//  Created by 高卫明 on 16/5/27.
//  Copyright © 2016年 YJB. All rights reserved.
//

#import "THHomeBtnCell.h"
#import "YJVerticalButton.h"
#import "Masonry.h"

NSString *caiFuBtnCellID = @"CaiFuMainBtnCell";
@implementation THHomeBtnCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nullable NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        NSMutableArray *buttons = [NSMutableArray array];
        NSArray *images = @[@"cpc_icon",@"th_home_flowEarn",@"task_icon",@"th_home_game",@"其它操作"];
        NSArray *titles = @[@"CPC赚钱",@"流量赚钱",@"任务赚钱",@"游戏赚钱",@"更多"];

        for (int i = 0; i < titles.count; i ++)
        {
            YJVerticalButton *button = [[YJVerticalButton alloc]init];
            button.tag = i + 10;
            [button setTitle:titles[i] forState:UIControlStateNormal];
            [button setTitleColor:kUIColorFromRGB(0x333333)  forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:12.0f];
            [button setImage:Image(images[i]) forState:UIControlStateNormal];
            [button addTarget:self action:@selector(CaiFuMainVCBtn:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:button];
            [buttons addObject:button];

        }
        //第一行添加约束
        [buttons mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:60 leadSpacing:12 tailSpacing:12];
        [buttons mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@0);
            make.height.mas_equalTo(self.mas_height);
        }];

    }
    return self;
}


- (void)CaiFuMainVCBtn:(UIButton *)sender
{
    THHomeBtnCellButtonType type = 0;
    switch (sender.tag)
    {
        case 10:
            type = THHomeButtonCellCPCEarnMoney;
           break;
        case 11:
            type =  THHomeBtnCellFlowEarnMoney;
            break;
        case 12:
            type = THHomeBtnCellTaskEarnMoney;
            break;
        case 13:
            type =  THHomeButtonCellGameEarnMoney;
        default:
            break;
        case 14:
            type = THHomeOtherBtnEarnMoney;
    }
    
    if (self.thButtonClickBlock)
        self.thButtonClickBlock(type);
    
}


@end
